import 'package:flutter/material.dart';

/// 自定义水波纹组件
///
/// 添加一层Ink是为了防止，子类的背景影响，导致水波纹无法显示
///
/// 子类有外边距的话，最好在此处设置，否则效果不会达到自己想要的
class EasyInkWell extends StatelessWidget {
  /// 子控件
  final Widget child;

  /// 背景色
  final Color? color;

  /// 渐变色背景色
  final Gradient? gradient;

  /// 圆角半径
  final double radius;

  /// 点击回调
  final void Function()? onTap;

  /// 外边距
  final EdgeInsetsGeometry? margin;

  /// 内边距
  final EdgeInsetsGeometry? padding;

  const EasyInkWell(
      {Key? key,
      required this.child,
      this.color,
      this.gradient,
      this.radius = 0,
      this.onTap,
      this.margin = const EdgeInsets.all(0),
      this.padding = const EdgeInsets.all(0)})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin,
      padding: padding,
      child: Material(
        borderRadius: BorderRadius.circular(radius),
        color: color,
        child: Ink(
          // color: Colors.white,
          decoration: new BoxDecoration(
            //不能同时”使用Ink的变量color属性以及decoration属性，两个只能存在一个
            color: color,
            //设置圆角
            borderRadius: BorderRadius.circular(radius),
            gradient: gradient,
          ),
          child: InkWell(
            borderRadius: BorderRadius.circular(radius),
            onTap: onTap,
            child: child,
          ),
        ),
      ),
    );
  }
}
